package org.je.database;

import java.util.ArrayList;
import java.util.List;

/**
 * @author fanyifeng
 */
public class DataTable
{
	private final String[]		meta;
	private final List<DataRow>	rows;

	public DataTable(String[] meta) {
		if (meta == null) {
			throw new NullPointerException("meta-is-null");
		}
		this.meta = meta;
		this.rows = new ArrayList<DataRow>(8);
	}

	public void putRowData(Object[] arr) {
		this.rows.add(new DataRow(meta, arr));
	}

	public int getColumnCount() {
		return meta.length;
	}

	public int getRowCount() {
		return rows.size();
	}

	public DataRow get(int i) {
		return rows.get(i);
	}
	
	public String getMeta(int i){
		return meta[i];
	}

	public String toShowSting(int max) {
		StringBuilder bf = new StringBuilder();
		for (int i = 0; i < meta.length; ++i) {
			bf.append(meta[i] + "\t");
		}
		bf.append("\r\n");
		for (int i = 0; i < max && i < rows.size(); ++i) {
			bf.append(rows.get(i).toString() + "\r\n");
		}
		return bf.toString();
	}
}
